/*
 * @Author: admin
 * @Date: 2022-02-26 09:30:48
 * @LastEditTime: 2022-07-07 09:30:48
 * @LastEditors: Please set LastEditors
 * @Description: 时间戳转换 --> 2022-07-07 09:30:48
 * @FilePath: src/utils/time.js
 * week 是否显示星期
 */
class Time {
    formatTime (current, isShow, getWeeks) {
      if (!current) {
        return
      }
      const date = new Date(current);
      const y = date.getFullYear();
      const m = (date.getMonth() + 1) < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
      const d = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
      const h = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
      const mi = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
      const s = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds();
      let week = date.getDay();
      let weeks = ["日","一","二","三","四","五","六"]
      let getWeek = '星期' + weeks[week]
      return {
        week: `${y}-${m}-${d} ${getWeek}`,
        date:`${y}-${m}-${d}`,
        dates:`${y}-${m}-${d} ${h}:${mi}:${s}`,
        hours:`${h}:${mi}:${s}`
      }
    }
    /* 日期格式化 */
    getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();

      if (type === 'start') {
        year = year - 60;
      } else if (type === 'end') {
        year = year + 2;
      }
      month = month > 9 ? month : '0' + month;;
      day = day > 9 ? day : '0' + day;
      return `${year}-${month}-${day}`;
    }
    // 不大于今天日期，且不小于90年前（d2今天日期，d1用户输入日期）
    CompareDate(d1, d2){
      var date1 = d2.split('-');
      var date2 = date1[0]-90+"-"+date1[1]+"-"+date1[2];
      return ((new Date(d1.replace(/-/g,"/"))) >= (new Date(d2.replace(/-/g,"/")))) || ((new Date(d1.replace(/-/g,"/"))) <= (new Date(date2.replace(/-/g,"/"))));
    }
  }
  export default new Time();